package com.totcy.atom.presenter;

import android.content.Context;

import com.totcy.atom.bean.User;
import com.totcy.atom.bean.response.VoidResponse;
import com.totcy.atom.model.LoginModel;
import com.totcy.atom.model.RegisterModel;
import com.totcy.atom.presenter.contract.LoginContract;
import com.totcy.atom.presenter.contract.RegisterContract;
import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;

import java.util.Map;

/**
 * description: 注册界面使用的presenter
 * author: Totcy
 * Date: 2018-10-26
 * Time: 16:13
 */

public class RegisterPresenter extends BasePresenterImpl<RegisterContract.View, RegisterContract.Model> implements RegisterContract.Presenter{

    public RegisterPresenter(Context context) {
        super(context);
    }

    @Override
    public RegisterContract.Model attachModel() {
        return new RegisterModel(mContext);
    }

    @Override
    public void doRegister(Map<String, Object> params) {
        if (isViewAttached()) {
            getView().showProgress("正在注册…");
        }
        getModel().doRegister(params, new RegisterContract.Model.DataCallback() {
            @Override
            public void onRegisterResult(User response) {
                if (isViewAttached()) {
                    getView().dismissProgress();
                    getView().onRegisterResult(response);
                }
            }

            @Override
            public void onRegisterFail(String message) {
                if (isViewAttached()) {
                    getView().dismissProgress();
                    getView().onRegisterFail(message);
                }
            }

        });
    }
}
